package com.milhouz.quizzdroid.bean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;

import com.milhouz.quizzdroid.db.QuizzDroidConstants;

public class ResponseList implements Parcelable {

	private List<Response> mResponses = new ArrayList<Response>();

	public ResponseList() {
	}

	public ResponseList(final Cursor cursor) {
		if (cursor != null) {
			String response = null;
			int index = 0;
			while (cursor.moveToNext()) {
				response = cursor.getString(cursor.getColumnIndex(QuizzDroidConstants.COLUMN_NAME_RESPONSE));
				mResponses.add(new Response(index, response));
				index++;
			}
			Collections.shuffle(mResponses);
		}
	}

	public int size() {
		return mResponses.size();
	}

	public Response get(int position) {
		return mResponses.get(position);
	}

	@Override
	public void writeToParcel(Parcel parcel, int flag) {
		parcel.writeList(mResponses);
	}

	public static final Creator<ResponseList> CREATOR = new Creator<ResponseList>() {
		@SuppressWarnings("unchecked")
		@Override
		public ResponseList createFromParcel(Parcel source) {
			ResponseList rl = new ResponseList();
			rl.mResponses = source.readArrayList(Response.class.getClassLoader());
			return rl;
		}

		@Override
		public ResponseList[] newArray(int arg0) {
			return null;
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}
}
